/*
 * @author zzr
 * @date: 2025/10/17  18:30
 * @description: 反转二叉树，将每一个节点的左右子树都进行交换
 * 注意在交换过程中，要将左右子树对应的引用进行交换，而不是仅仅将引用中的值进行交换~
 *
 */
public class Demo22 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        TreeNode tmp = root.left;
        root.left = root.right;
        root.right = tmp;

        invertTree(root.left);
        invertTree(root.right);
        return root;
    }
}
